#ifndef __CHANNEL_HPP__
#define __CHANNEL_HPP__

#include<iostream>
#include<string>
#include<unistd.h>
#include"Task.hpp"



class Channel
{
public:
	Channel(int wfd,pid_t who):_wfd(wfd),_who(who)
	{
		_name = "Channel-" + std::to_string(wfd) + "-" + std::to_string(who);
	}
	std::string Name()
	{
		return _name;
	}
	void Send(int cmd)
	{
		::write(_wfd,&cmd,sizeof(cmd));
	}
	void Close()
	{
		::close(_wfd);
	}
	pid_t Id()
	{
		return _who;
	}
	~Channel(){}

private:
	int _wfd;
	std::string _name;
	pid_t _who;
};


void Worker()
{
	while(1)
	{
		int cmd = 0;
		int n = ::read(0,&cmd,sizeof(cmd));
		if(n == sizeof(cmd))
		{
			tm.Excute(cmd);
		}
		else if(n == 0)
		{
			std::cout << "pid: " << getpid() << "quit..." << std::endl;
			break;
		}
		else
		{

		}
	}
}

#endif